Skip to content

fix(context): make provider-dropping note truthful for declared windows - #5174

Open
SummerC0zyR0ck wants to merge 1 commit into
apache:mainfrom
SummerC0zyR0ck:fix/context-provider-dropping-declared-window
Open

fix(context): make provider-dropping note truthful for declared windows#5174
SummerC0zyR0ck wants to merge 1 commit into
apache:mainfrom
SummerC0zyR0ck:fix/context-provider-dropping-declared-window

Conversation

@SummerC0zyR0ck

@SummerC0zyR0ck SummerC0zyR0ck commented Sep 11, 2026

Copy link
Copy Markdown

Summary

Fixes #5137

context_provider_dropping could be emitted for requests with an already-declared context window, but its Desktop and TUI copy always told the user to declare one. This produced contradictory system notes when context_window_overrun simultaneously acknowledged the existing declaration.

The note now records the declaration state at call time, using midTurnState.capacity as the Runtime authority. Rendering handles all three cases:

  • Declared window: acknowledges that the window is already configured and does not repeat the declaration recommendation.
  • Undeclared window: recommends declaring one so Maka can compact before sending.
  • Legacy records without the new field: uses a neutral explanation and does not infer current settings from mutable configuration.

The behavior is consistent across Runtime data, Desktop materialization, English, zh-CN, zh-TW, and TUI rendering.

Verification

The issue reproduction was confirmed on the current main branch: the existing declared-window Runtime fixtures passed while the zh-CN renderer still told the user to declare a context window. After the fix, the declaration state is recorded in the durable note and the rendered guidance is truthful for declared, undeclared, and legacy records.

Passed affected builds and regressions:

  • Runtime provider-dropping suite: 8/8 passed, including normal and slow-ledger-consumer variants. The tests verify both the diagnostic payload and the persisted contextWindowDeclared value.
  • UI materialization tests covering declared-window, undeclared-window, and legacy-note rendering.
  • TUI transcript rendering test for an already-declared context window.
  • Runtime, UI, runtime-host, eval, and CLI builds.
  • npm run format:check
  • npm run check:tui-copy
  • npm run check:locale-hygiene

The commit-time ASF license-header and protocol-epoch checks also passed.

The full repository test suite and full repository lint/typecheck suite were not run.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: OpenAI Codex investigated the defect and fixed, authored the implementation review, Runtime/UI/TUI regression tests.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — system notes now provide declaration-aware guidance and use a conservative fallback for legacy records.
  • No

@github-actions github-actions Bot added the effort/M Under 500 readable lines label Sep 11, 2026

@me2seeks me2seeks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR 5174 Review

结论

APPROVE
context_provider_dropping 现在在事件里记录调用时刻的声明状态 contextWindowDeclared: midTurnState.capacity !== undefinedai-sdk-turn.ts:1737),三处渲染(TUI pi-transcript.ts、Desktop materialize.ts、三语 copy)对 true/false/legacy 三分支处理,legacy 记录用中性措辞、不反查可变配置,与描述一致。

发现

不确定性(不发到 GitHub 的疑虑)

  • "truthful" 的边界情形:声明存在但 mid-turn compaction 未启用(historyCompact.midTurn.enabled !== true)时 midTurnState === undefined,note 根本不会发出(ai-sdk-turn.ts:1712 要求 midTurnState),所以不存在"声明了却没走 compaction 却仍说 will compact first"的矛盾路径——声明+midTurn 开启时 capacityresolveDeclaredContextWindow 注入(ai-sdk-compaction.ts:890),两者一致。论证成立。
  • 该 note 每个 session 只发一次(contextProviderDroppingReported latch),记录在 durable transcript 里的状态与"当时"一致,重放不重算——符合 PR "does not infer current settings from mutable configuration" 的设计。
  • pi-transcript.tsmaterialize.ts 两处各自 cast data 并判断 boolean,未共享一个 reader;重复但低风险,未发出。

✅ 对抗性审查(第一性原理 + 奥卡姆剃刀 + 证据核对)通过:未发现真实的 P0–P3 问题。@me2seeks 请把关是否 merge。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/M Under 500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(context): provider-dropping note asks to declare an already-declared window

2 participants